package com.hqyj.pojo;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    // 配置  @TableField(fill = FieldFill.INSERT)注解，插入时填充
    @Override
    public void insertFill(MetaObject metaObject) {
        System.out.println("MetaObject="+metaObject);
        // MetaObjectHandler setFieldValByName(String fieldName, Object fieldVal, MetaObject metaObject)
        // fieldName变量名，fieldVal填充值
        Date date = new Date();
        this.setFieldValByName("createTime",date,metaObject);


    }

    // 配置  @TableField(fill = FieldFill.INSERT_UPDATE)注解，插入与更新时填充
    @Override
    public void updateFill(MetaObject metaObject) {

        this.setFieldValByName("updateTime",new Date(),metaObject);
    }
}
